package com.carhailing.coupons.scheduled;

import com.carhailing.common.domain.order.CarPayRecord;
import com.carhailing.coupons.parent.PayHandle;
import com.carhailing.coupons.service.CouponsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: Gd  如果收不到支付回调  定时查询订单状态  避免重复回调
 * @package: com.carhailing.coupons.scheduled
 * @Project: Online_Taxi_Project
 * @Name: QueryTradeStatus
 * @Date: 2024-7-29 10:58
 */
@Component
@EnableScheduling // 开启定时任务
public class QueryTradeStatus {

    @Autowired
    private ApplicationContext applicationContext;

    @Autowired
    private CouponsOrderService couponsOrderService;

//    @Scheduled("")
    public void queryTradeStatus() {
        // 获取所有支付记录
        List<CarPayRecord> list = couponsOrderService.selectCarPayRecordStatus(0);
        list.forEach(carPayRecord -> {
            PayHandle bean = (PayHandle) applicationContext.getBean(carPayRecord.getPayRecordtype());
            try {
                bean.queryTradeOrder(carPayRecord.getPayRecordordernumber(), carPayRecord.getPayRecordtype());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
    }

}
